package _17作业._并发包编程题.t1;

import java.util.concurrent.CountDownLatch;

public class T1 {
    public static void main(String[] args) {
        CountDownLatch latch = new CountDownLatch(1);
        new Thread(new Print(latch)).start();
        new Thread(new Count(latch)).start();



    }
}
class Print implements Runnable{
    private CountDownLatch latch;

    public Print(CountDownLatch latch) {
        this.latch = latch;
    }

    @Override
    public void run() {
        System.out.println("开始计算");
        try {
            latch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("计算完毕");
    }
}

class Count implements Runnable{
    private CountDownLatch latch;

    public Count(CountDownLatch latch) {
        this.latch = latch;
    }

    @Override
    public void run() {
        int sum = 0;
        for (int i = 1; i <= 100; i++) {
            sum+=i;
        }
        System.out.println(sum);
        latch.countDown();
    }
}